package com.qianchang.microfinance.view.findings;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.Product;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 */

public class FindsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener{


    private Context mContext;
    private LayoutInflater inflater;
    private List<Product> productList;
    private OnItemClickListener mOnItemClickListener = null;


    public FindsAdapter(Context context){
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        productList = new ArrayList<Product>();
    }

    @Override
    public void onClick(View v) {
        if(mOnItemClickListener != null){
            mOnItemClickListener.onItemClick(v,(int)v.getTag());
        }
    }

    public static interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    public void setListProduct(List<Product> mproductList){
        if(mproductList != null){
            productList = mproductList;
        }
        notifyDataSetChanged();
    }

    public void clearData(){
        if(productList != null){
            productList.clear();
        }
        notifyDataSetChanged();
    }

    public final List<Product> getItems() {
        return productList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_findadapter_layout,parent,false);
        ProductHolder productHolder = new ProductHolder(view);
        view.setOnClickListener(this);
        return productHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ProductHolder productHolder = (ProductHolder)holder;
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        if(productList != null && productList.size() != 0){
//            return productList.size();
            return 3;
        }
        return 3;
    }

    public class ProductHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_ie_id)
        ImageView titleImg;

        public ProductHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
